package com.gdougms.config;

import com.gdougms.interceptor.AdminOperationInterceptor;
import com.gdougms.interceptor.UserGetOneInfoInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**@Title 拦截器
 * @Description 实现对用户非法使用接口的拦截
 * @Author iceF
 * @Date 2021/6/19
*/
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    UserGetOneInfoInterceptor userGetOneInfoInterceptor;

    @Autowired
    AdminOperationInterceptor adminOperationInterceptor;

    /**@Title 添加拦截器
     * @Description 把定义好的拦截器添加进来，否则不会生效
     * @Param registry
     * @Author iceF
     * @Date 2021/6/19
    */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        this.userInterceptor(registry);
        this.adminOperationInterceptor(registry);
    }

    private void userInterceptor(InterceptorRegistry registry){
        registry.addInterceptor(userGetOneInfoInterceptor)
                .addPathPatterns("/getUsers/**","/getUser")
                .excludePathPatterns("/**");
    }

    private void adminOperationInterceptor(InterceptorRegistry registry){
        registry.addInterceptor(adminOperationInterceptor)
                .addPathPatterns("/userList","/deleteUser","/addUser")
                .excludePathPatterns("/**");
    }
}
